package com.cn.steam.iam.mapper.iam;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cn.steam.iam.model.IamUserDetails;
import com.cn.steam.iam.model.po.IamPermission;
import com.cn.steam.iam.model.po.IamUser;
import com.cn.steam.iam.model.po.IamUserGranter;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

import static com.cn.steam.foundation.common.model.CommonConstant.DATA_SOURCE_KEY_IAM;


/**
 * @author huangzz
 */
@DS(DATA_SOURCE_KEY_IAM)
public interface IamUserMapper extends BaseMapper<IamUser> {
	@Select("SELECT * FROM iam_user WHERE login_name = #{loginName}")
	IamUserDetails selectByLoginName(@Param("loginName") String loginName);

	@Select("SELECT * FROM iam_user_granter WHERE user_id = #{userId}")
	List<IamUserGranter> listUserGranter(@Param("userId")String userId);

	List<IamPermission> listUserPermissions(String userId);

	@Select("SELECT * FROM iam_user WHERE partner_id = #{partnerId} AND type = #{userType} LIMIT 1")
	IamUser selectByPartnerIdAndType(@Param("partnerId")String partnerId, @Param("userType")String userType);
	@Select("SELECT * FROM iam_user WHERE user_id != #{partnerId}")
	IPage<IamUser> testList(@Param("page")Page<IamUser> page, @Param("partnerId")String partnerId);

}
